<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
$groupname=array(
		'0'=>'大众免费版',
		'1'=>'商业授权版',
		'2'=>'年费商业版',
		'3'=>'永久商业版',
);
if($_RQ['op']=='get'){
	$cloud=core_setting('cloud');
	//print_r($cloud);exit;
	if($cloud){
		$res=cloud_request('cloud.domain.set');
		$cloud['group']=$res['group'];
		$cloud['username']=$res['username'];
		core_setting('cloud',$cloud);
	}else{
		exi('请先设置云服务参数！','error');
	}
	$groupid = $cloud['group'] ? $cloud['group'] : '0';
	$jy_xiu = core_setting('jy_xiu');
	$return['item'] = array_fields(array('name','logo','domain','user_appid','user_appsecret','renzheng'),$jy_xiu);
	$return['item']['group'] = $groupname[$groupid];
	$htmls=array(
			'type'=>'edit',
			'post'=>'post',
			'desc'=>'基本信息',
			'tabs'=>array(
				'0'=>array('op'=>'get','title'=>'基本设置'),
			),
			'edit'=>array(
				array('type'=>'string','title'=>'会员组','read'=>true, 'name'=>'group', 'help'=>'[知悉]：大众免费版无法设置：版权信息,H5场景独立域名,PC站,手机站,小游戏,小程序去版权等,--> <a style="color:red" target="_blank" href="http://s.jinyunweb.com/manage/index.php?plugin=core&action=fuwu.vip">移步升级</a>'),
				array('type'=>'string','title'=>'场景站点名称','name'=>'name', 'help'=>'用于尾页信息设置' ),
				array('type'=>'image','title'=>'场景站点LOGO','name'=>'logo', 'help'=>'用于默认分享等图标' ),
				array('type'=>'string','title'=>'JS分享appid','name'=>'user_appid', 'help'=>'填写公众号appid,该公众号必须添加下面的域名为JS安全域名' ),
				array('type'=>'string','title'=>'JS分享appsecret','name'=>'user_appsecret', 'help'=>'填写公众号appsecret,该公众号必须添加下面的域名为JS安全域名' ),
				array('type'=>'upfile','title'=>'JS认证文件','name'=>'renzheng','ftype'=>'other','help'=>'本功能用于上传认证文件到站点根目录！例如，小程序或公众号设置授权域名时，提示需要上传认证文件。请下载下来，并在此处上传。'),
				array('type'=>'string','title'=>'场景独立域名','name'=>'domain', 'help'=>'用于场景独立域名访问(不用加http://,例如：xiu.jinyunweb.com)，--> <a style="color:red" target="_blank" href="http://s.jinyunweb.com/manage/index.php?plugin=core&action=article.show&nosession=1&id=111">设置教程</a>' ),
			)
		);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'name'=>trim($postdata['name']),
		'logo'=>trim($postdata['logo']),
		'domain'=>trim($postdata['domain']),
		'user_appid'=>trim($postdata['user_appid']),
		'user_appsecret'=>trim($postdata['user_appsecret']),
		
	);
	$cloud=core_setting('cloud');
	$groupid = $cloud['group'] ? $cloud['group'] : '0';
	if($groupid){	
		if($postdata['renzheng']){
			if($postdata['domain']){
				$filename=pdo_getcolumn('core_attachment',array('attachment'=>$postdata['renzheng']),'title');
				if(preg_match('/[^\w\.-]/',$filename)){
					exi('认证文件名不合法！','error');
				}
				$file_data=cfc('files')->source_read($postdata['renzheng']);
				if(strlen($file_data)>100){
					exi('上传失败！认证文件内容超过限制！'.$file_data,'error');
				}
				$url='?s=home/index/addrenzheng/&filename='.$filename.'&filedata='.$file_data;
				$res=model('jy_xiu/model')->xiu_request($url);
				$data['renzheng']=$postdata['renzheng'];
			}else{
				//exi('未设置独立域名，不允许上传证书！','error');
			}
		}
		core_setting('jy_xiu',$data);
	}else{
		exi('大众免费版不能设置！','error');
	}
	exi('设置成功！');
}

?>